package com.theta.gateway.facade.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.theta.gateway.biz.dto.request.RoutePredicateSaveRequest;
import com.theta.gateway.biz.dto.request.RouteSaveRequest;
import com.theta.gateway.biz.service.DynamicRouteService;
import com.theta.gateway.biz.service.RouteCfgService;
import com.theta.gateway.infra.common.base.Result;
import com.theta.gateway.infra.common.utils.GatewayRequestUtil;
import com.theta.gateway.infra.routecfg.model.dataobject.response.RouteInfoDO;
import com.theta.gateway.infra.routecfg.model.dataobject.response.RouteInfoFilterDO;
import com.theta.gateway.infra.routecfg.model.dataobject.response.RouteInfoPredicateDO;




@RestController
@RequestMapping("saas/gateway/router/test")
public class TestController {
	
	@Autowired
	private DynamicRouteService dynamicRouteService;
//	@Autowired
//	private SecurityService securityService;
	@Autowired
	private RouteCfgService routeCfgService;
	
	
//	@GetMapping("add")
//	public Result<Object> add(ServerHttpRequest request){
//		RouteInfoDO dto=new RouteInfoDO();
//		dto.setRouteId("saas-gateway-center");
//		dto.setUri("uri:lb://saas-gateway-center");
//		dto.setOrder(1);
//		dto.addPredicate(RouteInfoPredicateDO.builder()
//				.name("Path")
//				.build()
//				.addArgs("_genkey_0", "saas/gateway/**")
////				.addArgs("_genkey_1", "/saas/sso1/**")
//				);
//		dto.addFilter(RouteInfoFilterDO.builder()
//				.name("AddRequestHeader")
//				.build()
//				.addArgs("_genkey_0", "testtoken,gbs11111")
//				);
//		
//		this.dynamicRouteService.saveRouteInfo(dto);
////		this.dynamicRouteService.deleteRouteInfo(dto.getRouteId());
//		return Result.success();
//		
//	}
	
	@GetMapping("all")
	public Result<Object> all(ServerHttpRequest request){
		System.out.println(GatewayRequestUtil.getToken(request, "testtoken"));
		return Result.success(this.dynamicRouteService.queryAllRoute());
	
	}
	
	@GetMapping("cache")
	public Result<Object> cache(@RequestParam("serviceKey") String serviceKey){
		return Result.success(this.routeCfgService.getCacheServiceRoute(serviceKey));
	
	}
	
//	@GetMapping("test-nacos")
//	public Result<Object> testNacos(ServerHttpRequest request){
//		this.securityService.auth("test", "1111");
//		return Result.success();
//	
//	}

}
